package com.yishusmt.mobsmt.controller;

import com.yishusmt.mobsmt.advice.HandleException;
import com.yishusmt.mobsmt.dto.base.Result;
import com.yishusmt.mobsmt.dto.request.EditPasswordReq;
import com.yishusmt.mobsmt.dto.request.UserLoginReq;
import com.yishusmt.mobsmt.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *  用户注册
 *
 * @author zhangyi
 * @date 2018/8/9 11:45
 */
@RestController
@Api(description = "用户登录控制")
@RequestMapping("/userLogin")
@Slf4j
public class UserLoginController {

    @Resource
    private LoginService loginService;

    /**
     * 用户登陆控制
     *
     * @param userLoginReq
     * @return
     */
    @PostMapping("/login")
    @ApiOperation(value = "用户登录",httpMethod = "POST")
    public Result login(@RequestBody UserLoginReq userLoginReq){
        Result result = null;
        try{
            result = loginService.login(userLoginReq);
        }catch (HandleException e){
            log.error("用户登录错误！");
        }
        return result;
    }

    /**
     * 用户修改密码
     *
     * @param editPasswordReq
     * @return
     */
    @PostMapping("/editPassword")
    @ApiOperation(value = "用户修改密码",httpMethod = "POST")
    public Result editPassword(@RequestBody EditPasswordReq editPasswordReq){
        return loginService.editPassword(editPasswordReq);
    }

}
